"""
HumanBreakerInputFrame.py

Created by Zach Epolito on 09/24/2008.

$Id: HumanBreakerInputFrame.py 325 2008-10-17 02:20:55Z malerba89 $
"""

import sys
import string
import os
from Tkinter import *

class HumanBreakerInputFrame(Frame):
    """allows a human to input the breaker move. this frame is inserted
       into the GameInputFrame and callsback after it collects the input
    """

    responseButs = [Button(),Button(),Button(),Button()]
    colorIndex = ["red","blue","yellow","green","white","black"]
    
    def __init__(self,master,doneHandler, title, **kv):
        """constructor. doneHandler is the callback function to be called
           when the input is collected
        """
        Frame.__init__(self,master,kv)
        
        # These variables are globals representing the values of the response
        self.responseVals = [0,0,0,0]

        #this is the functor value to be invoked
        self.doneHandler = doneHandler

        self.responseButs[0] = Button(self, command=self.changeButtonZero, bg=self.colorIndex[0])
        self.responseButs[0].config(height=2, width=2, bd = 10)
        self.responseButs[1] = Button(self, command=self.changeButtonOne, bg=self.colorIndex[0])
        self.responseButs[1].config(height=2, width=2, bd = 10)
        self.responseButs[2] = Button(self, command=self.changeButtonTwo, bg=self.colorIndex[0])
        self.responseButs[2].config(height=2, width=2, bd = 10)
        self.responseButs[3] = Button(self, command=self.changeButtonThree, bg=self.colorIndex[0])
        self.responseButs[3].config(height=2, width=2, bd = 10)
        self.label = Label(self, text = title)

        self.doneButton = Button(self, text="Done", command=self.handleDone)
        self.doneButton.config(height=2, width=12, bd = 3)

        #Place the buttons
        self.responseButs[0].grid(row=0, column=1)
        self.responseButs[1].grid(row=0, column=2)
        self.responseButs[2].grid(row=0, column=3)
        self.responseButs[3].grid(row=0, column=4)
        self.doneButton.grid(row=0, column=5)
        if (title != ""):
            self.label.grid(row=0, column = 0)
    
    """changes the color of the first button"""
    def changeButtonZero(self):
        self.changeButton(0)
        #self.responseButs[0].config (text=self.responseVals[0])

    """changes the color of the second button"""
    def changeButtonOne(self):
        self.changeButton(1)
        #self.responseButs[1].config (text=self.responseVals[1])

    """changes the color of the third button"""
    def changeButtonTwo(self):
        self.changeButton(2)
        #self.responseButs[2].config (text=self.responseVals[2])

    """changes the color of the fourth button"""
    def changeButtonThree(self):
        self.changeButton(3)
        #self.responseButs[3].config (text=self.responseVals[3])

    def changeButton(self, buttonNum):
        self.responseVals[buttonNum] = self.responseVals[buttonNum] + 1
        self.responseVals[buttonNum] = self.responseVals[buttonNum] % 6
        self.responseButs[buttonNum].config (bg=self.colorIndex[self.responseVals[buttonNum]])

    def handleDone(self):
        """callback"""
        self.doneHandler(self.responseVals)

    def reset(self):
        """reset the buttons"""
        self.responseVals = [0,0,0,0]
        self.responseButs[0].config (text=self.responseVals[0])
        self.responseButs[1].config (text=self.responseVals[1])
        self.responseButs[2].config (text=self.responseVals[2])
        self.responseButs[3].config (text=self.responseVals[3])
